package chapt17networkProgram;

public class MultiThreadDown {
    public static void main(String[] args) throws Exception {
        //初始化DownUtil对象
//        final DownUtil downUtil = new DownUtil("http://www.crazyit.org/attachments/month_1403/1403202355ff6cc9a4fbf6f14a.png", "ios.png", 4);
//        final DownUtil downUtil = new DownUtil("https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/exp/w=500/sign=77c3e60080d6277fe912323818391f63/472309f79052982282cc4b78d0ca7bcb0b46d48a.jpg", "ios.png", 4);
        //书本原代码工具类
//        final DownUtil downUtil = new DownUtil("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg", "ios.png", 4);
        //解决403的工具类
        final DownUtilFor403 downUtilFor403 = new DownUtilFor403("https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg", "ios.png", 4);
        //https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/exp/w=500/sign=77c3e60080d6277fe912323818391f63/472309f79052982282cc4b78d0ca7bcb0b46d48a.jpg
        //开始下载
//        downUtil.download();
        downUtilFor403.download();
        new Thread(() -> {
            while(downUtilFor403.getCompleteRate() < 1){
                //每隔0.1秒查询一次完成进度
                //GUI程序中可根据该进度来绘制进度条
                System.out.println("已完成：" + downUtilFor403.getCompleteRate());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("线程中断异常");
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
